package com.mobilesales.android.adapters;

import java.util.List;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;

public class ProductImageAdapter extends BaseAdapter {

	private Context context;
	private List<Bitmap> images;

	public ProductImageAdapter(Context ctx, List<Bitmap> images) {
		this.context = ctx;
		this.images = images;
	}

	public int getCount() {
		if (images != null)
			return images.size();
		return 0;
	}

	public Object getItem(int position) {
		if (images != null) {
			try {
				return images.get(position);
			} catch (IndexOutOfBoundsException e) {
				return null;
			}
		}
		return null;
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
        ImageView imageView = new ImageView(context);

        imageView.setLayoutParams(new Gallery.LayoutParams(150, 100));
        imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
        imageView.setImageBitmap(images.get(position));
        return imageView;

	}

}
